Skip to content

staticaddr: validate server address parameters#1137

Merged
hieblmi merged 1 commit into
lightninglabs:masterfrom
hieblmi:param-validation
May 11, 2026
Merged

staticaddr: validate server address parameters#1137
hieblmi merged 1 commit into
lightninglabs:masterfrom
hieblmi:param-validation

Conversation

@hieblmi

@hieblmi hieblmi commented May 7, 2026

Copy link
Copy Markdown
Collaborator

This PR adds validation of server address parameters during the creation of static addresses.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the security and robustness of the static address creation process by introducing server-side parameter validation. By ensuring that the parameters provided by the server conform to expected constraints before they are utilized in address generation, the system is better protected against malformed or malicious inputs.

Highlights

  • Input Validation: Added strict validation for server-provided address parameters, including checks for nil responses, zero expiry, and invalid CSV flags.
  • Security Constraints: Implemented a maximum CSV expiry limit of 200 days (28,800 blocks) to prevent excessively long lock times on static addresses.
  • Test Coverage: Introduced comprehensive unit tests to verify parameter validation logic and ensure boundary conditions are handled correctly.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@hieblmi hieblmi requested review from bhandras and starius May 7, 2026 07:21

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces validation for server-provided parameters during the generation of new static addresses. A new validateServerAddressParams function ensures that the server response is not nil and that the expiry value is non-zero, within acceptable bounds, and contains valid CSV flags. Unit tests have been expanded to cover these validation scenarios. The review feedback recommends further strengthening the validation by explicitly checking for the presence of the server's public key and adding a corresponding test case.

Comment thread staticaddr/address/manager.go
Comment thread staticaddr/address/manager_test.go

@bhandras bhandras left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! 🎉

@hieblmi hieblmi force-pushed the param-validation branch 2 times, most recently from df971c5 to dcc6d58 Compare May 8, 2026 13:32
@hieblmi hieblmi self-assigned this May 8, 2026

@starius starius left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🎯
Great fix!

Comment thread staticaddr/address/manager.go Outdated
return fmt.Errorf("missing server address parameters")
}

if len(params.GetServerKey()) == 0 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we validate that it is a serialized compresses EC public key?
https://pkg.go.dev/github.com/btcsuite/btcd/btcec/v2#IsCompressedPubKey
It checks both the length and the first byte.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the improvement, I added it.

Comment thread staticaddr/address/manager.go Outdated
Comment on lines +259 to +260
return fmt.Errorf("invalid static address CSV flags: %x",
expiry)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rephrase it to be more clear:
"static address expiry does not fit into CSV: %x"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}
}

func newServerNewAddressResponse(expiry uint32) *swapserverrpc.ServerNewAddressResponse {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

godoc is missing

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@hieblmi hieblmi force-pushed the param-validation branch from 2960c90 to 6aa6979 Compare May 11, 2026 06:59
@hieblmi hieblmi merged commit de279bc into lightninglabs:master May 11, 2026
10 checks passed
@hieblmi hieblmi deleted the param-validation branch May 11, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants